package graph.tests;

import junit.framework.*;

import graph.*;

public class DijkstraTest extends TestCase {
    public final static String A = "A";
    public final static String B = "B";
    public final static String C = "C";
    public final static String D = "D";
    public final static String E = "E";
    private final static String F = "F";
    private final static String G = "G";
    private final static String H = "H";
    
    private Dijkstra dij;
    
    private MockGraph graph;

    public DijkstraTest(String s) {
        super(s);
    }

    protected void setUp() {
        graph = new MockGraph();
        graph.buildGraphTest();
        dij = new Dijkstra(graph);
    }

    protected void tearDown() {
    }

    public void testGetShortestRoute() {

    }

    public void testGetShortestWeightDistance() {

        assertEquals(9, dij.getShortestWeightDistance(A, C));

        assertEquals(9, dij.getShortestWeightDistance(B, B));

        //assertEquals(9, dij.getShortestWeightDistance(E, E));
    }
    
    /**
     * Olivier Daroux sent me this test and the code to fix a bug in
     * the compareTo method in the class PriorityQueue.QueueElement.
     * Thanks to him.
     */
    public void testBUGFindShortestPath() {
        AdjacencyMatrixGraph buggedGraph = new AdjacencyMatrixGraph(8);
        buggedGraph.addVertex(A);
        buggedGraph.addVertex(B);
        buggedGraph.addVertex(C);
        buggedGraph.addVertex(D);
        buggedGraph.addVertex(E);
        buggedGraph.addVertex(F);
        buggedGraph.addVertex(G);
        buggedGraph.addVertex(H);
        buggedGraph.addEdge(A, B, 1);
        buggedGraph.addEdge(B, A, 1);
        buggedGraph.addEdge(B, C, 1);
        buggedGraph.addEdge(C, B, 1);
        buggedGraph.addEdge(C, D, 1);
        buggedGraph.addEdge(D, C, 1);
        buggedGraph.addEdge(C, E, 1);
        buggedGraph.addEdge(E, C, 1);
        buggedGraph.addEdge(C, F, 1);
        buggedGraph.addEdge(F, C, 1);
        buggedGraph.addEdge(F, G, 1);
        buggedGraph.addEdge(G, F, 1);
        buggedGraph.addEdge(F, H, 1);
        buggedGraph.addEdge(H, F, 1);
        
        dij = new Dijkstra(buggedGraph);
        assertEquals("A-B-C-F-H", dij.getShortestPath(A, H).toString());
    }
    
}
